package com.change.declare.declare.BO;

import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component
@Data
public class MainOrderIDGenerator {
    public String ClientCode;

    @Autowired
    StringRedisTemplate stringRedisTemplate;

    public String MainOrderSN() {
        String orderSN = ClientCode;
        ValueOperations<String, String> ops = stringRedisTemplate.opsForValue();
        Long serialID = ops.increment("Seq_MainOrderID_" + ClientCode);
        String serialNo = String.format("%03d", serialID);
        Date dtNow = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
        orderSN += simpleDateFormat.format(dtNow);
        orderSN += serialNo;

        return orderSN;
    }
}
